import 'package:dio/dio.dart';
import 'dart:async';
import 'dart:io';
import '../config/service_url.dart';

Future postRequest<T>(String url, {T data}) async {
  try {
    print('----->开始获取数据,url:${url}<-----');
    Response response;
    Dio dio = Dio();
    dio.options.contentType =
        ContentType.parse('application/x-www-form-urlencoded');
    response = (data == null)
        ? await dio.post(servicePath[url])
        : await dio.post(servicePath[url], data: data);
    if (response.statusCode == 200) {
      return response.data;
    } else {
      throw Exception('后端接口出现异常，请检测代码和服务器情况.........');
    }
  } catch (e) {
    print('Error--->>${e}');
  }
}
